<form class="layui-form page-content p-4">
	<h3 class="h3-title">知识分类</h3>
	{eq name="$id" value="0"}
	<table class="layui-table">
		<tr>
			<td class="layui-td-gray">父级分类<font>*</font></td>
			<td>
				<select name="pid" lay-verify="required" lay-reqText="请选择父级分类">
				  <option value="0">作为顶级分类</option>
				  {volist name="$cates" id="v"}
				  <option value="{$v.id}" {eq name="$pid" value="$v.id"}selected=""{/eq}>{$v.title}</option>
				  {/volist}
				</select>
			</td>
			<td class="layui-td-gray">分类名称<font>*</font></td>
			<td>
				<input type="text" name="title" lay-verify="required" autocomplete="off" placeholder="请输入分类名称" lay-reqText="请输入分类名称" class="layui-input">
			</td>
			<td class="layui-td-gray">排序</td>
			<td>
				<input type="text" name="sort" placeholder="请输入排序，数字" value="0" autocomplete="off" class="layui-input">
			</td>
		</tr>
		<tr>
			<td class="layui-td-gray">描述</td>
			<td colspan="5"><textarea name="desc" placeholder="请输入描述，可空" class="layui-textarea"></textarea></td>
		</tr>
	</table>
	{else/}
	<table class="layui-table">
		<tr>
			<td class="layui-td-gray">父级分类<font>*</font></td>
			<td>
				<select name="pid" lay-verify="required" lay-reqText="请选择父级分类">
				  <option value="0">作为顶级分类</option>
				  {volist name="$cates" id="v"}
				  <option value="{$v.id}" {eq name="$detail.pid" value="$v.id"}selected=""{/eq}>{$v.title}</option>
				  {/volist}
				</select>
			</td>
			<td class="layui-td-gray">分类名称<font>*</font></td>
			<td>
				<input type="text" name="title" value="{$detail.title}" lay-verify="required" autocomplete="off" placeholder="请输入分类名称" lay-reqText="请输入分类名称" class="layui-input">
			</td>
			<td class="layui-td-gray">排序</td>
			<td>
				<input type="text" name="sort" value="{$detail.sort}" placeholder="请输入排序，数字" value="0" autocomplete="off" class="layui-input">
			</td>
		</tr>
		<tr>
			<td class="layui-td-gray">描述</td>
			<td colspan="5"><textarea name="desc" placeholder="请输入描述，可空" class="layui-textarea">{$detail.desc}</textarea></td>
		</tr>
	</table>
	{/eq}
	<div style="padding: 10px 0">
		<input type="hidden" name="id" value="{$id}">
		<button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform">立即提交</button>
		<button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
</form>
<script>
	function openInit() {
		var form = layui.form,
			layer = layui.layer,
			tool = layui.tool;
		form.render();
		  
		//监听提交
		form.on('submit(webform)', function(data){
			let callback = function (e) {
				layer.msg(e.msg);
				if (e.code == 0) {
					location.reload();
				}
			}
			tool.post("/admin/kcate/add",data.field,callback);
			return false;
		});
	}
</script>